package com.corn.flink;

import com.corn.flink.lesson4.Event;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author JimWu
 * @date 2023/4/17 14:02
 **/
public class FlinkFilterSplitStreamDemo {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Event> ds = env.fromElements(
                new Event("add", 1000),
                new Event("delete", 2000),
                new Event("update", 3000),
                new Event("select", 5000),
                new Event("add", 6000),
                new Event("delete", 7000),
                new Event("select", 8000),
                new Event("select", 9000),
                new Event("select", 10000),
                new Event("select", 11000)
        );

        // 使用filter分流
        SingleOutputStreamOperator<Event> addStream = ds.filter(event -> event.type.equals("add"));
        SingleOutputStreamOperator<Event> selectStream = ds.filter(event -> event.type.equals("select"));

        addStream.print("addStream");
        selectStream.print("selectStream");

        env.execute();
    }
}
